<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/mui.css" rel="stylesheet" />
    <link href="../css/header.css" rel="stylesheet" />
</head>

<body>
    <!-- 头部 -->
    <header class="mui-bar mui-bar-nav title">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color:white;"></a>
        <a id="link_submit_search" class="mui-icon mui-icon-right-nav mui-pull-right" style="color:white;font-size:14px;line-height:25px;">搜索</a>
        <h1 class="mui-title title-color">添加朋友</h1>
    </header>
    <!--主体部分  -->
    <div class="mui-content">
        <div class="mui-input-row">
            <input id="txt_friend_username" type="text" class="mui-input-speech mui-input-clear" placeholder="搜索好友" />
        </div>
    </div>
    <script src="../js/mui.js"></script>
    <script src="../js/app.js"></script>
    <script type="text/javascript">
    mui.init();
    mui.plusReady(function() {
        //获取全局用户信息
        var user = app.getUserGlobalInfo();
        //获取搜索框对象
        var txt_friend_username = document.getElementById("txt_friend_username");
        //为搜索添加触摸事件
        var link_submit_search = document.getElementById("link_submit_search");
        link_submit_search.addEventListener("tap", function() {
            var friendName = txt_friend_username.value; //获取搜索框所输入的内容
            if (!app.isNotNull(friendName)) {
                app.showToast("请输入要搜索的好友名称", "error");
                // 获取焦点
                link_submit_search.focus();
            } else {
                plus.nativeUI.showWaiting("请稍后");
                // 与后端联调
                mui.ajax(app.serverUrl + "/user/searchFriend?myUserId=" + user.id + "&friendUserName=" + friendName, {
                    type: 'get', //HTTP请求类型
                    timeout: 10000, //超时时间设置为10秒；
                    headers: { 'Content-Type': 'application/json' },
                    success: function(data) {
                        // 关闭等待框
                        plus.nativeUI.closeWaiting();
                        if (data.status == 200) {
                            console.log(JSON.stringify(data));
                            mui.openWindow({
                                url: "searchFriendsResult.html",
                                id: "searchFriendsResult.html",
                                extras: {
                                    friend: data.data
                                }
                            });
                        } else {
                            app.showToast(data.msg, "error");
                        }
                    }
                });
            }
        });
    });
    </script>
</body>

</html>